<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        position: absolute;
        left: 0;
        width: 100px;
        height: 100px;
        background-color: pink;
      }
    </style>
  </head>
  <body>
    <button id="btn200">200</button>
    <button id="btn400">400</button>
    <button id="btn800">800</button>
    <hr />
    <div class="box"></div>
    <script src="animate.js"></script>
    <script>
      // 1.获取元素
      var btn200 = document.querySelector("#btn200");
      var btn400 = document.querySelector("#btn400");
      var btn800 = document.querySelector("#btn800");
      var div = document.querySelector(".box");
      btn200.addEventListener("click", function () {
        // 调用函数
        animate(div, 200);
      });

      btn400.addEventListener("click", function () {
        // 调用函数
        animate(div, 400);
      });
      btn800.addEventListener("click", function () {
        // 调用函数
        animate(div, 800);
      });
    </script>
  </body>
</html>
